package model;

//file handlers
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.File;
//xml handlers
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
//general utility classes
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.HashMap;


public class AcolytePlayer
{
  //properties for the player, like life
  private HashMap<String, Integer> playerStats;
  //list of the zones the player controls
  private List<AcolyteZone> zones;
  //the game this player is playing in
  private AcolyteGame myGame;
  
  public AcolytePlayer(AcolyteDeck myDeck, AcolyteGameType parameters)
  {
    zones = new LinkedList<AcolyteZone>();
    zones.add(myDeck);
    for(String az:parameters.getZones())
    {
      //zones.add(new AcolyteZone(az));
    }
  }
  
  public boolean viewZone(AcolyteZone zone)
  {
    if(zone.getOwner() == this || zone.isPublic())
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  
  public void showZone(AcolyteZone toShow, AcolytePlayer toWhom)
  {
   //TODO make this actually show the zone 
  }
  
  
  public void changeZone(AcolyteCard toMove, AcolyteZone targetZone)
  {
      toMove.getZone().remove(toMove);
      targetZone.add(toMove);
  }
  
  public boolean modifyCard(AcolyteCard toModify, String property, String newValue)
  {
    if(queryControl(toModify))
    {
      toModify.set(property, newValue);
      return true;
    }
    return false;
  }
  
  public boolean moveTopCard(AcolyteZone sourceZone, AcolyteZone targetZone)
  {
    targetZone.add(sourceZone.topCard());
    sourceZone.remove(sourceZone.topCard());
    return true;
  }
  
  
  //Change a stat of a player, for example life
  public int modifyStat(String statName, int newValue)
  {
    playerStats.put(statName, newValue);
    return newValue;
  }
  
  public int incrementStat(String statName)
  {
    if(playerStats.get(statName) != null)
    {
      playerStats.put(statName, playerStats.get(statName) + 1);
    }
    return playerStats.get(statName);
  }
  
  public int decrementStat(String statName)
  {
    if(playerStats.get(statName) != null)
    {
      playerStats.put(statName, playerStats.get(statName) - 1);
    }
    return playerStats.get(statName);
  }
  
  private boolean queryControl(AcolyteCard toCheck)
  {
    for(AcolyteZone az:zones)
    {
      if(az.contains(toCheck))
      {
        return true;
      }
    }
    return false;
  }
  
}